package com.sgcc.fj.pmos.e_fj_home.activity;


import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sgcc.fj.pmos.arouter.home.HomeArouterPath;
import com.sgcc.fj.pmos.common.base.MvpBaseRecycleActivity;
import com.sgcc.fj.pmos.e_fj_home.adapter.InfomationMsgListAdapter;
import com.sgcc.fj.pmos.e_fj_home.bean.InfomationMsgBean;
import com.sgcc.fj.pmos.e_fj_home.contract.InfomationMessageListContract;
import com.sgcc.fj.pmos.e_fj_home.presenter.InfomationMessageListPresenter;

/**
 * 信息披露--首页---信息列表
 */
@Route(path = HomeArouterPath.HOME_INFOMATIONMESSAGELIST)
public class InfomationMessageListActivity extends MvpBaseRecycleActivity<InfomationMsgBean.DataBean.ListBean, InfomationMessageListPresenter> implements InfomationMessageListContract.View {

    private InfomationMsgListAdapter mInfomationMsgListAdapter;
    private String mLabel, mInfoCode = "";

    @Override
    protected void receiveIntentExtras() {
        super.receiveIntentExtras();
        showLoading();
        mLabel = getIntent().getStringExtra("label");
        mInfoCode = getIntent().getStringExtra("infoCode");
    }

    @Override
    public String getTitleText() {
        return mLabel;
    }

    @Override
    protected InfomationMessageListPresenter createPresenter() {
        return new InfomationMessageListPresenter();
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        mInfomationMsgListAdapter = new InfomationMsgListAdapter(mContext);
        mInfomationMsgListAdapter.setOnItemClickListener(new InfomationMsgListAdapter.OnItemClickListener() {
            @Override
            public void itemClickListener(int position, InfomationMsgBean.DataBean.ListBean bean) {
                //交易机构基本信息 jyjgJbxx
                if ("jyjgJbxx".equals(bean.getIpParameterConfiguration().getInfoCode())) {
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_TRADINGINSTITUTIONBASICINFO)
                            .navigation();
                } else if ("dlyhQyjbxx".equals(mInfoCode)) {
                    //发电企业--企业基本信息---fdqyQyjbxx  电力用户--企业基本信息---dlyhQyjbxx 售电公司--企业基本信息---sdgsQyjbxx
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_BASICINFORMATIONENTERPRISE)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .navigation();
                } else if ("fdqyQyjbxx".equals(mInfoCode)) {
                    //发电企业--企业基本信息---fdqyQyjbxx  电力用户--企业基本信息---dlyhQyjbxx 售电公司--企业基本信息---sdgsQyjbxx
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_FDBASICINFORMATIONENTERPRISE)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .navigation();
                } else if ("sdgsQyjbxx".equals(mInfoCode)) {
                    //发电企业--企业基本信息---fdqyQyjbxx  电力用户--企业基本信息---dlyhQyjbxx 售电公司--企业基本信息---sdgsQyjbxx
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_SDBASICINFORMATIONENTERPRISE)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .navigation();
                } else if ("fdqyDcjzxx".equals(mInfoCode)) {
                    //电厂机组信息
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_DCJZXX)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .withString("operateDate", bean.getOperateDate())
                            .withString("readAmount", bean.getReadAmount() + "")
                            .withString("publishType", bean.getPublishType())
                            .navigation();
                } else if ("sdgsZcrycl".equals(mInfoCode)) {
                    //售电公司---------资产人员材料
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_SDRYCL)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .withString("operateDate", bean.getOperateDate())
                            .withString("readAmount", bean.getReadAmount() + "")
                            .withString("publishType", bean.getPublishType())
                            .navigation();
                } else if ("dlyhQyydxx".equals(mInfoCode)) {
                    //电力用户-----企业用电信息
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_DLYHQYYDXX)
                            .withString("guid", bean.getGuid())
                            .withString("sourceName", bean.getSourceName())
                            .withString("operateDate", bean.getOperateDate())
                            .withString("readAmount", bean.getReadAmount() + "")
                            .withString("publishType", bean.getPublishType())
                            .navigation();
                } else {
                    ARouter.getInstance()
                            .build(HomeArouterPath.HOME_INFOMATIONCONTENT)
                            .withString("title", bean.getTitle())
                            .withString("operateDate", bean.getOperateDate())
                            .withString("publishType", bean.getPublishType())
                            .withString("content", bean.getContent())
                            .withString("attachment", bean.getAttachment())
                            .withString("readAmount", bean.getReadAmount() + "")
                            .navigation();
                }
            }
        });
        return mInfomationMsgListAdapter;
    }

    @Override
    public void getDataRequest(int listSize, boolean isloading) {
        super.getDataRequest(listSize, isloading);
        mPresenter.getMsg(mInfoCode, listSize, isloading);
    }

    @Override
    public void getInfomationMsgListSuccess(InfomationMsgBean response) {
        dismissLoading();
        if (response.getData() != null) {
            loadinglayout.showContent();
            if (response.getData().getList() != null) {
                int total = response.getData().getTotal();
                int pageNum = response.getData().getPageNum();
                int pageSize = response.getData().getPageSize();
                boolean nextPage = false;
                if (total != 0) {
                    // 优先计算总页数
                    int totalPage = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
                    //下一页等于当前页+1,但不能超过总页数界限
                    nextPage = pageNum + 1 <= totalPage ? true : false;
                }
                loadSuccess(nextPage, response.getData().getList());
            } else {
                loadinglayout.showEmpty();
            }
        } else {
            loadinglayout.showError();
        }
    }

    @Override
    public void getInfomationMsgListFailed() {
        loadinglayout.showError();
    }
}
